<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        const soldInfo = {
            apple: {
                //销售数量
                sold: 100,
                //剩余数量
                surplus: 10,
                //价格
                price: 6000
            },
            mi: {
                sold: 120,
                surplus: 20,
                price: 2000
            },
            huawei: {
                sold: 80,
                surplus: 30,
                price: 3500
            },
            oppo: {
                sold: 60,
                surplus: 40,
                price: 3500
            }
        }
        // 遍历对象soldInfo第一级, 生成数组，数组元素{key:sold}
        /**
         * type: sold surplus   price
         */
        const sortGoods = (type) => {
            const arr = []
            for (const key in soldInfo) {
                const obj = { name: key, [type]: soldInfo[key][type] }
                arr.push(obj)
            }

            arr.sort((a, b) => a[type] - b[type])
            console.log(arr)
            return arr.map(item => item.name)
        }
        const newArr = sortGoods('surplus')
        console.log(newArr);


        const stateArr = [
            { status: 100, msg: '未支付' },
            { status: 200, msg: '已支付' },
            { status: 300, msg: '已收货' },
            { status: 400, msg: '已退货' }]
        const list = [
            { id: 1, name: '商品1', content: '描述', price: 89, status: 100 },
            { id: 2, name: '商品2', content: '描述2', price: 39, status: 100 },
            { id: 3, name: '商品3', content: '描述3', price: 139, status: 200 },
            { id: 4, name: '商品4', content: '描述4', price: 339, status: 300 },
            { id: 4, name: '商品5', content: '描述4', price: 339, status: 400 }
        ]
        const demo = () => {
            stateArr.forEach(item => {
                const newList = list.filter(sub => sub.status === item.status)
                console.log(newList);
            })
        }
        demo()
    </script>
</body>

</html>